package com.hmsg.health.controller.admin;


import com.hmsg.health.bean.Dto.AdminUserTaskDto;
import com.hmsg.health.bean.domain.BannerDo;
import com.hmsg.health.bean.domain.TaskTypeDo;
import com.hmsg.health.bean.enums.StatusCode;
import com.hmsg.health.bean.vo.BannerReqVo;
import com.hmsg.health.bean.vo.TaskFirstReqVo;
import com.hmsg.health.dao.BannerDao;
import com.hmsg.health.param.ResponseResult;
import com.hmsg.health.security.IgnoreSecurity;
import com.hmsg.health.security.OpenApi;
import com.hmsg.health.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(value = "运营系统banner相关", tags = { "运营系统banner相关" })
@Slf4j
@Controller
@RequestMapping("/banner")
public class AdminBannerController {
    @Autowired
    private CommonService commonService;
    @Autowired
    private BannerDao bannerDao;

    @GetMapping("/list")
    @ApiOperation(value="运营系统banner相关", notes="运营系统banner相关" ,httpMethod="GET")
    @ResponseBody
    @IgnoreSecurity
    public ResponseResult< List<BannerDo>> queryList() {
       List<BannerDo> bannerDoList= bannerDao.findAll();
       return new ResponseResult< List<BannerDo>>(StatusCode.SYSTEM_SUCCESS, bannerDoList);
    }



    @PostMapping("/addBanner")
    @ApiOperation(value="添加首页banner", notes="添加首页banner" ,httpMethod="POST")
    @ResponseBody
    @IgnoreSecurity
    @OpenApi
    public ResponseResult<Object> addFirstTasks( @ApiParam(name = "添加首页banner", value = "传入json格式", required = true)
                                                 @RequestBody @Validated BannerReqVo vo) {

        BannerDo banner=new BannerDo();
        banner.setImage(vo.getBannerImg());
        banner.setSort(vo.getSort());
        banner.setStatus(vo.getState());
        commonService.saveBanner(banner);
        return new ResponseResult<Object>(StatusCode.SYSTEM_SUCCESS, null);

    }



    @PostMapping("/updateBanner")
    @ApiOperation(value="编辑首页banner", notes="编辑首页banner" ,httpMethod="POST")
    @ResponseBody
    @IgnoreSecurity
    @OpenApi
    public ResponseResult<Object> updateBanner( @ApiParam(name = "编辑首页banner", value = "传入json格式", required = true)
                                                 @RequestBody @Validated BannerReqVo vo) {

        BannerDo banner=new BannerDo();
        banner.setImage(vo.getBannerImg());
        banner.setSort(vo.getSort());
        banner.setStatus(vo.getState());
        banner.setId(vo.getBannerId());
        commonService.updateBanner(banner);
        return new ResponseResult<Object>(StatusCode.SYSTEM_SUCCESS, null);
    }


    @PostMapping("/deleteBanner")
    @ApiOperation(value="删除首页banner", notes="删除首页banner" ,httpMethod="POST")
    @ResponseBody
    @IgnoreSecurity
    @OpenApi
    public ResponseResult<Object> deleteBanner( @ApiParam(name = "删除首页banner", value = "传入json格式", required = true)
                                                @RequestBody @Validated BannerReqVo vo) {
        commonService.deleteBanner(vo.getBannerId());
        return new ResponseResult<Object>(StatusCode.SYSTEM_SUCCESS, null);
    }


}
